package com.h.heal.mapper;

import com.h.heal.entity.User;
import com.h.heal.entity.Video;
import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Component;

import java.util.List;

@Mapper
@Component
public interface UserMapper {

    @Select("SELECT *FROM `user` WHERE user_name=#{user_name} AND user_pwd= #{user_pwd}")
    User findByNameAndPwd(@Param("user_name") String user_name, @Param("user_pwd") String user_pwd);

    @Select("SELECT *FROM `user` WHERE user_name=#{user_name} ")
    User findByName(@Param("user_name") String user_name);

    @Insert("INSERT INTO `heal`.`user` (`user_name`, `user_pwd`, `user_vip`, `user_state`) VALUES (#{user_name}, #{user_pwd}, 'free', 'normal')")
    void register(User user);


    @Select("SELECT * FROM `user`")
    List<User> findAll();

    @Select("SELECT * FROM `user` where user_name=#{user_name}")
    List<User> findByUser_name(String user_name);

    @Select("SELECT * FROM `user` where user_pwd=#{user_pwd}")
    List<User> findByUser_pwd(String user_pwd);

    @Select("SELECT * FROM `user` where user_vip=#{user_vip}")
    List<User> findByUser_vip(String user_vip);

    @Select("SELECT * FROM `user` where user_state=#{user_state}")
    List<User> findByUser_state(String user_state);

    @Delete("delete from `user` where user_uid=#{user_uid}")
    void deleteByUser_uid(int id);

    @Select("SELECT * FROM `user` where user_uid=#{user_uid}")
    User findById(int id);

    @Update("UPDATE `heal`.`user` SET `user_name` = #{user_name}, `user_pwd` = #{user_pwd}, `user_vip` = #{user_vip}, `user_state` = #{user_state}  WHERE `user_uid` = #{user_uid}")
    void edit(User user);


    List<User> findBySearch(String user_name, String user_pwd, String user_vip, String user_state);


    int count(String user_name, String user_pwd, String user_vip, String user_state);

    //分页查找
    List<User> findBySearchWithPage(String user_name, String user_pwd, String user_vip, String user_state, int startPageIndex, int pageSize);


}
